/**
 * while实现二分查找
 * @param array 源数组
 * @param target 目标值
 * @returns 目标值索引
 */
function binarySearchWithLoop(array: Array<number>, target: number, leftIndex: number, rightIndex: number): number {
    const midIndex = Math.floor((leftIndex + rightIndex) / 2);
    console.log(`索引范围：${leftIndex + "---" + rightIndex}`);
    console.warn(`目标范围：${rightIndex - leftIndex}`);
    if (array[midIndex] === target) {
        return midIndex;
    } else if (array[midIndex] > target) {
        return binarySearchWithLoop(array, target, leftIndex, midIndex - 1);
    } else {
        return binarySearchWithLoop(array, target, midIndex + 1, rightIndex);
    }
}
function demo() {
    //@ts-ignore
    const mockArray = Array.from(new Array(Math.pow(2, 22)), (item, index) => {
        return index + 1;
    });
    binarySearchWithLoop(mockArray, 500, 0, mockArray.length - 1);
}
export default {
    name: "二分查找(递归)",
    core: binarySearchWithLoop,
    event: demo,
};
